import 'package:flutter/material.dart';
import 'package:flutter/physics.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:frametrim/route/Routes.dart';
import 'package:frametrim/utility/Internationalization.dart';
import 'package:frametrim/utility/sp_utils.dart';
import 'package:get/get.dart';
import 'package:oktoast/oktoast.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import 'activity/splashPage.dart';

final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();

class AppScene extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => AppSceneState();
}

class AppSceneState extends State<AppScene> {
  @override
  void initState() {
    super.initState();
    SPUtil.getInstance();
  }

  @override
  Widget build(BuildContext context) {
    /*最外层一定要使用MaterialApp*/
    return OKToast(
        //getX:第二步
        child: RefreshConfiguration(
            headerBuilder: () => ClassicHeader(),
            // Configure the default header indicator. If you have the same header indicator for each page, you need to set this
            footerBuilder: () => ClassicFooter(),
            // Configure default bottom indicator
            headerTriggerDistance: 80.0,
            // header trigger refresh trigger distance
            springDescription:
                SpringDescription(stiffness: 170, damping: 16, mass: 1.9),
            // custom spring back animate,the props meaning see the flutter api
            maxOverScrollExtent: 100,
            //The maximum dragging range of the head. Set this property if a rush out of the view area occurs
            maxUnderScrollExtent: 0,
            // Maximum dragging range at the bottom
            enableScrollWhenRefreshCompleted: true,
            //This property is incompatible with PageView and TabBarView. If you need TabBarView to slide left and right, you need to set it to true.
            enableLoadingWhenFailed: true,
            //In the case of load failure, users can still trigger more loads by gesture pull-up.
            hideFooterWhenNotFull: true,
            // Disable pull-up to load more functionality when Viewport is less than one screen
            enableBallisticLoad: true,
            // trigger load more by BallisticScrollActivity
            child: GetMaterialApp(
              debugShowCheckedModeBanner: false,
              title: '成品油政府端',
              initialRoute: Routes.SPLASH,
              getPages: Routes.getPages,
              translations: Internationalization(),
              theme: ThemeData(
                primarySwatch: Colors.blue,

                ///点击水波纹颜色
                splashColor: Colors.transparent,
                primaryColor: Colors.greenAccent,
                dividerColor: Colors.transparent,
                //去除按钮内部自带padding
                buttonTheme: ButtonThemeData(
                  minWidth: 0,
                  height: 0,
                  padding: EdgeInsets.zero, // 可以设置为zero,
                ),
              ),
              builder: EasyLoading.init(),
              localizationsDelegates: [
                RefreshLocalizations.delegate,
                GlobalWidgetsLocalizations.delegate,
                GlobalMaterialLocalizations.delegate,
                GlobalCupertinoLocalizations.delegate
              ],
              supportedLocales: const [
                Locale('zh'),
              ],
              locale: const Locale('zh', 'CN'),
              //设置默认语言
              fallbackLocale:
                  const Locale('zh', 'CN'), //在配置错误的ExpansionTile情况下使用的语言
            )));
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
